﻿
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Welcome to ClassChimp</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/login.css" rel="stylesheet">
    <script src="js/jquery-1.12.1.js"></script>
    <script type="text/javascript">
      if(window.top != window.self) {
        parent.location.reload()
      }
    </script>
</head>

<body>

<div class="container">

    <form class="form-signin">
        <h2 class="form-signin-heading">欢迎登录 ClassChimp</h2>
        <p class="alert"></p>
        <label for="useraccount" class="sr-only">账号</label>
        <input type="email" id="useraccount" name="useraccount" class="form-control" placeholder="账号" required autofocus>
        <label for="userpwd" class="sr-only">密码</label>
        <input type="password" id="userpwd" name="userpwd" class="form-control" placeholder="密码" required>
        <button class="btn btn-lg btn-primary btn-block" id="login_btn" type="button">登录</button>

    </form>

</div> <!-- /container -->

</body>
<script>
    $("body").bind("keyup",function(event) {
      if(event.keyCode==13){
        login();
      }
    });
    $('#login_btn').on('click', login );

    function login() {
      var useraccount = $('#useraccount').val();
      var userpwd = $('#userpwd').val();
      $.ajax({
        type:'post',
        url:'/api/user/login',
        data:{
          account: useraccount,
          password: userpwd,
        },
        success:function (msg) {
          if(msg.status.code == 0)
            location.href = 'index.html';
          else {
            $('.alert').text('用户名或密码错误！');
          }
        }
      });
    }
</script>
</html>
